﻿using Edu.Abstracts;
using Edu.Contracts;
using Edu.Entitys;
using Edu.Utilities;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Edu.Services
{
    public class AchievementAppService : AsyncCrudAppService<AppAchievement, AchievementDto, Guid, PagedAndSortedResultRequestDto,
                            AchievementCreateUpdateDto, AchievementCreateUpdateDto>, IAchievementAppService
    {

        private IUrlHelper urlHelper;

        public AchievementAppService(IUrlHelper urlHelper, IRepository<AppAchievement, Guid> repository)
            : base(repository)
        {
            this.urlHelper = urlHelper;
        }


        public override async Task<PagedResultDto<AchievementDto>> GetListAsync(PagedAndSortedResultRequestDto input)
        {
            var result = await base.GetListAsync(input);

            foreach (var item in result.Items)
            {
                item.ActiveIcon = urlHelper.Normalize(item.ActiveIcon);
                item.DisableIcon = urlHelper.Normalize(item.DisableIcon);
            }
            return result;
        }
    }
}
